package com.cmict.data.form.api.task;

import com.cmict.data.form.api.task.dto.BpmColumnDTO;
import com.cmict.data.form.api.task.dto.FormBaseDTO;
import com.cmict.data.framework.common.pojo.CommonResult;
import com.cmict.data.form.api.enums.ApiConstants;
import com.cmict.data.form.api.task.dto.BpmFormDTO;
import com.cmict.data.form.api.task.dto.SysFormDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 字典数据 API 接口
 *
 * @author awesome
 */
@FeignClient(name = ApiConstants.NAME) // TODO awesome：fallbackFactory =
@Api(tags = "RPC 服务 - 部门")
public interface FormDataApi {

    String PREFIX = ApiConstants.PREFIX + "/info";

    /**
     * 获取表单信息
     *
     * @param formIds 表单ids
     * @return 表单属性和组件属性
     */
    @GetMapping(PREFIX + "/map")
    @ApiOperation("获取表单组件属性")
    @ApiImplicitParam(name = "formIds", value = "表单id", example = "1", required = true, allowMultiple = true)
    Map<Long, FormBaseDTO> getFormMap(@RequestParam("formIds") Set<Long> formIds);

    /**
     * 获取表单属性和组件属性
     *
     * @param formId 表单id
     * @return 表单属性和组件属性
     */
    @GetMapping(PREFIX + "/config")
    @ApiOperation("获取表单配置")
    @ApiImplicitParam(name = "formId", value = "表单id", example = "1", dataTypeClass = Long.class)
    BpmFormDTO getFormConfig(@RequestParam("formId") Long formId);

    @GetMapping(PREFIX + "/form_id")
    @ApiOperation("获取表单id")
    @ApiImplicitParam(name = "tableName", value = "表单id", example = "1", dataTypeClass = String.class)
    Long getFormIdByTableName(@RequestParam("tableName") String tableName);

    @GetMapping(PREFIX + "/menu_id")
    @ApiOperation("获取menu_id列表")
    Set<Long> getUserMenuId();

    @GetMapping(PREFIX + "/list")
    @ApiOperation("获取表单信息")
    @ApiImplicitParam(name = "menuIds", value = "菜单id", example = "1", dataTypeClass = String.class)
    List<SysFormDTO> getSysFormByUseMenuIds(@RequestParam("menuIds") String menuIds);

    @GetMapping(PREFIX + "/selectListRelease")
    List<SysFormDTO> selectListRelease();

    @GetMapping(PREFIX + "/getManageMenuId")
    Collection<? extends Long> getManageMenuId();

    @GetMapping(PREFIX + "/getSysFormByFormMenuIds")
    Set<SysFormDTO> getSysFormByFormMenuIds(String formMenuId);


    @ApiOperation("获取所有数据")
    @GetMapping(PREFIX + "/getAllData")
    CommonResult selectAllData(String tableName);

    @ApiOperation("根据FormId和FormRecordId获取数据")
    @GetMapping(PREFIX + "/getDataByIds")
    CommonResult getDataByIds(@RequestParam("formRecordId")Integer formRecordId,
                              @RequestParam("formId")Long formId);

    @ApiOperation("根据FormId和dataId获取数据")
    @GetMapping(PREFIX + "/getDataBydataIds")
    CommonResult getDataBydataIds(@RequestParam("dataId")Integer dataId,
                              @RequestParam("formId")Long formId);

    @GetMapping(PREFIX + "/getSysFormById")
    SysFormDTO getSysFormById(@RequestParam("forId")  Long forId);

    @GetMapping(PREFIX + "/getColumns")
    @ApiImplicitParam(name = "formId", value = "表单id", example = "1", dataTypeClass = Long.class)
    CommonResult<List<BpmColumnDTO>> getColumnByFormId(@RequestParam("formId")  Long formId);

    @ApiOperation("自定义表修改数据")
    @GetMapping(value = "/updata")
    CommonResult updata(@RequestParam("tableName") String tableName,
                        @RequestParam("formRecordId") Integer formRecordId,
                        @RequestParam("approveStatus") Integer approveStatus);
}
